package com.shell.customer.register.controller;

import com.shell.bee.base.annotation.Logging;
import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.base.utils.SystemUtil;
import com.shell.bee.base.utils.SystemUtil.SystemMode;
import com.shell.bee.entity.mvc.RetMsg;
import com.shell.customer.base.service.CusCheckService;
import com.shell.customer.register.service.RegisterService;
import com.shell.customer.register.vo.RegisterVo;
import com.shell.framework.utils.VerifyCodeUtil;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RegisterController {
	@Autowired
	private RegisterService registerService;
	@Autowired
	private CusCheckService cusCheckService;
	protected final Log logger = LogFactory.getLog(getClass());

	@RequestMapping
	@Logging(module = "����", methods = "��������")
	public RetMsg customerRegister(RegisterVo registerVo) throws Exception {
		if (StringUtil.notEmpty(registerVo.getPassword())) {
			RetMsg msg = VerifyCodeUtil.checkVerifyCode(registerVo.getVerifyCode());
			if (!"success".equals(msg.getType())) {
				return msg;
			}
		}
		this.registerService.customerRegister(registerVo);
		Map<String, String> m = new HashMap();
		m.put("entId", registerVo.getCusId());
		return new RetMsg("success", true, "����������", m);
	}

	@RequestMapping
	@Logging(module = "����", methods = "��������������")
	public RetMsg sendSms(@RequestParam(name = "phoneNo") String phoneNo) throws Exception {
		String smsCode = this.registerService.sendSMS(phoneNo);
		boolean show = false;
		if (!SystemUtil.SystemMode.prod.equals(SystemUtil.getSystemMode())) {
			show = true;
		}
		return new RetMsg("success", show, "����������������,��������" + smsCode);
	}

	@RequestMapping
	@Logging(module = "����", methods = "��������������������������")
	public boolean checkCustomerExist(String cusName) throws Exception {
		return this.cusCheckService.checkCusExist(cusName);
	}
}
